package box;

import java.awt.Color;
import java.awt.Panel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Janela extends JFrame {

    Panel p = new Panel();

    public Janela() {
        super("Cores");

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 300);

        //p.setBackground(Color.green);

        JButton bVermelho = new JButton("Vermelho");
        p.add(bVermelho);
        bVermelho.addMouseListener(new ManipuladorEvento(Color.red));

        JButton bVerde = new JButton("Verde");
        p.add(bVerde);
        bVerde.addMouseListener(new ManipuladorEvento(Color.green));

        JButton bAzul = new JButton("Azul");
        p.add(bAzul);
        bAzul.addMouseListener(new ManipuladorEvento(Color.blue));
        //p.add(new JLabel("Cor Clicada"));


        //p.addMouseListener(new ManipuladorEvento());
        this.setContentPane(p);
        setVisible(true);

    }

    private class ManipuladorEvento extends MouseAdapter {

        Color cor;

        public ManipuladorEvento(Color cor) {
            this.cor = cor;
        }
        @Override 
        public void mouseClicked(MouseEvent me){
            p.setBackground(cor);
        }

        /*
         * @Override public void mouseClicked(MouseEvent me) { JButton
         * botaoClicado = ((JButton) me.getSource()); if
         * (botaoClicado.getText().equals("Vermelho")) {
         * p.setBackground(Color.RED); } else if
         * (botaoClicado.getText().equals("Verde")) {
         * p.setBackground(Color.GREEN); } else if
         * (botaoClicado.getText().equals("Azul")) {
         * p.setBackground(Color.BLUE); } }
    }
         */

        /*
         * private class ManipuladorEventoVermelho extends MouseAdapter {
         *
         * @Override public void mouseClicked(MouseEvent me) {
         * p.setBackground(Color.RED); } }
         *
         * private class ManipuladorEventoVerde extends MouseAdapter {
         *
         * @Override public void mouseClicked(MouseEvent me) {
         * p.setBackground(Color.GREEN); } }
         *
         * private class ManipuladorEventoAzul extends MouseAdapter {
         *
         * @Override public void mouseClicked(MouseEvent me) {
         * p.setBackground(Color.BLUE); }
    */}
         
        public static void main(String[] args) {
            Janela j = new Janela();
        }
    }
